package com.ittaoli.controller;


import com.ittaoli.entity.User;
import com.ittaoli.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/main")
public class MuneController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("/menu")
    @ResponseBody
    public Object menu(HttpSession session){
        User u= (User) session.getAttribute("loginUser");
        Map<String,Object> map=new HashMap<>();
        map.put("userId",u.getLoginId());
        map.put("userName",u.getName());
        List<Map<String,Object>> maps=menuService.selectId(u.getId());
        map.put("menus",maps);
        return map;
    }

    @RequestMapping("/enit")
    @ResponseBody
    public void remove(HttpSession session){
       session.removeAttribute("loginUser");
    }
}
